package com.telra.app.subway;

import com.google.transit.realtime.NyctSubway;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * User: jamesarlet
 * Date: 3/14/13
 * Time: 9:13 PM
 */
public class DataFeed {

    public static final String DATAFEED_URL = "http://datamine.mta.info/mta_esi.php?key=52e1f3758140fad2128ac59b03e6d9f4";



    public static void main (String args[])  {


        try {
            URL url = new URL(DATAFEED_URL);
            URLConnection con = url.openConnection();
            con.setConnectTimeout(1000);
            con.setReadTimeout(1000);

            InputStream in = con.getInputStream();
            NyctSubway.NyctTripDescriptor tripDescriptor = NyctSubway.NyctTripDescriptor.parseFrom(in);
            System.out.println(tripDescriptor);

            System.out.println("**********************************************");

            NyctSubway.NyctFeedHeader header = NyctSubway.NyctFeedHeader.parseFrom(in);
            System.out.println(header);


            //BufferedReader buff = new BufferedReader(new InputStreamReader(in));
            //String line;
            //while ((line = buff.readLine()) != null) {
            //    System.out.println(line);
            //}
            in.close();



            //byte[] b = new byte[1024];
            //int i = 0;
            //while ( ( i = in.read(b)) != -1 )  {
            //    System.out.println(new String(b));
            //}
            //in.close();

        } catch (MalformedURLException e) {
            e.printStackTrace();

        } catch (IOException e) {
            e.printStackTrace();
        }


    }


}
